<template>
  <div style="position: relative">
    <div class="flex_right">
      <right-toolbar @queryTable="getList" :columns="columns">
      </right-toolbar>
    </div>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="序号" align="center" prop="order" width="50" />
      <el-table-column v-if="columns[18].visible" label="设备编号" align="center" prop="noticeType" min-width="130">
        <template slot-scope="scope">
          <el-link @click="handledetailed(scope.row)" type="primary">{{ scope.row.equipmentNum || '-' }}</el-link>
        </template>
      </el-table-column>
      <el-table-column v-if="columns[0].visible" label="资产编号" align="center" prop="noticeType" min-width="130">
        <template slot-scope="scope">
          <el-link @click="handledetailed(scope.row)" type="primary">{{ scope.row.assetNum || '-' }}</el-link>
        </template>
      </el-table-column>
      <el-table-column v-if="columns[19].visible" label="设备名称" align="center" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.equipmentName || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[1].visible" label="设备状态" align="center" min-width="160">
        <template slot-scope="scope">
          <dict-tag :options="statusDevicedist" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column v-if="columns[2].visible" label="使用状态" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.userStatusName || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[3].visible" label="品牌" align="center" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.brand || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[4].visible" label="负责人" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.headName || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[5].visible" label="规格型号" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.model || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[6].visible" label="所属部门" align="center" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.deptName || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[7].visible" label="位置" align="center" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.placeName || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[8].visible" label="单位" align="center" min-width="60">
        <template slot-scope="scope">
          {{ scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.unitName || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[20].visible" label="供应商" align="center" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.supplierName || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[9].visible" label="采购日期" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.purchaseTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[10].visible" label="采购金额（元）" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.purchasePrice === null ? '****' : scope.row.purchasePrice }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[11].visible" label="验收日期" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.acceptanceTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[12].visible" label="保质期至" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.shelfLife || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[13].visible" label="启用日期" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.enableTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[14].visible" label="预计报废日期" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.estimatedScrapTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[15].visible" label="净值（元）" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.netWorth === null ? '****' : scope.row.netWorth }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[21].visible" label="计量设备" align="center" min-width="120">
        <template slot-scope="scope">
          {{ meterageFlag[scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.meterageFlag] || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[16].visible" label="计量编号" align="center" min-width="160">
        <template slot-scope="scope">
          {{ scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.meterageNum || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[22].visible" label="类别" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.typeName || '-' }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="状态" align="center"  min-width="120">
        <template slot-scope="scope">
          <span :class="{red:scope.row.status=='1'}" v-if="scope.row.status=='1'">
            {{statusFlag[scope.row.status] || '-'}}
          </span>
          <span v-else>
            {{statusFlag[scope.row.status] || '-'}}
          </span>
        </template>
      </el-table-column> -->
      <el-table-column v-if="columns[17].visible" label="备注" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.remark || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[23].visible" label="附件" align="center" min-width="120">
        <template slot-scope="scope">
          <el-link :disabled="!(scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.file)" icon="el-icon-document"
            type="primary" :href="scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.file" target="_blank">
            附件资料</el-link>
        </template>
      </el-table-column>
      <el-table-column v-if="columns[24].visible" label="创建部门" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.deptName || '-' }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns[25].visible" label="创建人" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.createBy || '-' }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" min-width="300" fixed="right" align="center">
        <template slot-scope="scope">
          <el-button size="small" v-hasPermi="['ledger_reuse_update']" icon="el-icon-edit" type="primary"
            @click="handleUpdate(scope.row)">编辑</el-button>
          <!-- <el-button
            v-if="scope.row.status === '0'"
            size="small"
            type="danger"
            @click="handleDelete(scope.row)"
          >禁用</el-button> -->
          <el-button :disabled="!(scope.row.userStatus === '0')" v-hasPermi="['ledger_reuse_enable']" size="small"
            type="success" icon="el-icon-unlock" @click="handleDelete(scope.row)">设备启用</el-button>
          <el-button v-hasPermi="['ledger_reuse_img']" size="small" type="primary" icon="el-icon-view"
            @click="handleSelectImage(scope.row.equipmentBaseVo && scope.row.equipmentBaseVo.image)">图片
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="card-div">
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="$parent.$refs['search'].handlechaxun()" />
    </div>
    <template v-if="ImageOpen">
      <DialogImage :src="ImageSrc"></DialogImage>
    </template>
    <!-- 修改设备基值 -->
    <template v-if="open">
      <addbaseValue :title="title" :rowObj="rowObj"></addbaseValue>
    </template>
    <!-- 查看设备基值详情 -->
    <template v-if="opendetailed">
      <detailed :rowObj="detailedObj"></detailed>
    </template>
    <template v-if="openEnable">
      <EnableDialog :EnableObject="EnableObject"></EnableDialog>
    </template>
  </div>
</template>

<script>
import { getequipmentlist, getcolumnslist, Updatecolumns } from "@/api/equipment/equipment.js";

export default {
  name: "reuse",
  // dicts: ['sys_notice_status', 'sys_notice_type'],
  components: {
    addbaseValue: () => import('../form/addbaseValue.vue'),
    detailed: () => import('../form/detailed.vue'),
    EnableDialog: () => import('../form/enabledialog.vue')
  },
  data () {
    return {
      // 遮罩层
      ImageOpen: false,
      ImageSrc: '',
      loading: true,
      opendetailed: false,
      openEnable: false,
      EnableObject: {},
      detailedObj: {},
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dictdatalist: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层表格数据
      noticeList: [],
      rowObj: {},
      // 弹出层标题
      title: "修改设备台账",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'equipmentAccountId',
        isAsc: 'desc'//倒叙
      },
      // 列信息
      columns: [
        { key: 0, label: `资产编号`, visible: true },
        { key: 1, label: `设备状态`, visible: true },
        { key: 2, label: `使用状态`, visible: true },
        { key: 3, label: `品牌`, visible: true },
        { key: 4, label: `负责人`, visible: true },
        { key: 5, label: `规格型号`, visible: true },
        { key: 6, label: `所属部门`, visible: true },
        { key: 7, label: `位置`, visible: true },
        { key: 8, label: `单位`, visible: true },
        { key: 9, label: `采购日期`, visible: true },
        { key: 10, label: `采购金额(元)`, visible: true },
        { key: 11, label: `验收日期`, visible: true },
        { key: 12, label: `保质期至`, visible: true },
        { key: 13, label: `启用日期`, visible: true },
        { key: 14, label: `预计报废日期`, visible: true },
        { key: 15, label: `净值(元)`, visible: true },
        { key: 16, label: `计量编号`, visible: true },
        { key: 17, label: `备注`, visible: true },
        { key: 18, label: `设备编号`, visible: true, disabled: true },
        { key: 19, label: `设备名称`, visible: true, disabled: true },
        { key: 20, label: `供应商`, visible: true, disabled: true },
        { key: 21, label: `计量设备`, visible: true, disabled: true },
        { key: 22, label: `类别`, visible: true, disabled: true },
        { key: 23, label: `附件`, visible: true, disabled: true },
        { key: 24, label: `创建部门`, visible: true },
        { key: 25, label: `创建人`, visible: true }
      ],
    };
  },
  watch: {
    columns: {
      handler (value) {
        this.updateFlag()
      },
      deep: true
    }
  },
  computed: {
    purchasePriceDisplayFlag () {//默认不展示采购金额
      return this.$store.state.reuseVariable.PriceDisplay
    }
  },
  created () {
    if (this.$store.state.user.isCondition !== '2') {
      this.getList();
    }
    this.getcolumns();
  },
  mounted () {
    // console.log(this.dict.type.sys_notice_status);
  },
  methods: {
    /**更新动态列数据 */
    async updateFlag () {
      let params = {
        viewKey: 'equipment_account',
        columnFlag: JSON.stringify(this.columns)
      }
      await Updatecolumns(params)
      // this.getcolumns()
    },
    /**查询动态列数据 */
    async getcolumns () {
      let { data: data } = await getcolumnslist({ 'viewKey': 'equipment_account' })
      let str = ''
      if (data.length !== 0) {
        data.map(item => {
          if (item.viewKey === 'equipment_account') {
            // str = JSON.parse(eval('(' + item.columnFlag + ')'))
            str = JSON.parse(item.columnFlag)
            return false
          }
        })
        this.columns = str
      }
    },
    handleSelectImage (src) {
      this.ImageOpen = true
      this.ImageSrc = src
    },
    /** 查询列表 */
    async getList (value) {
      this.loading = true;
      let objects = value || {}
      let params = {
        ...this.queryParams,
        ...objects,
        'equipmentBaseVo.equipmentName': objects.equipmentName || '',//设备名称
        'equipmentBaseVo.typeName': objects.typeName || '',//设备类别
        purchasePriceDisplayFlag: this.purchasePriceDisplayFlag,
        'params[userStatuses]': '0,1,2,4'
      }
      //  let data = await getdatalist({ dictType: 'base_unit' })
      //  this.dictdatalist=data.data
      getequipmentlist(params).then(response => {
        this.noticeList = response.data && response.data.map((item, index) => {
          return {
            ...item,
            order: index + 1
          }
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 打开详细弹窗
    handledetailed (row) {
      console.log(row.equipmentAccountId);
      this.$parent.$parent.$parent.$parent.tabIndex = true
      this.$parent.$parent.$parent.$parent.activeName = '6'
      this.$parent.$parent.$parent.$parent.rowObj = row
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.rowObj = row
      this.open = true
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 启用禁用按钮操作 */
    handleDelete (row) {
      this.EnableObject = row
      this.openEnable = true
      // const noticeIds = row.equipmentNum || '无名称'
      // this.$confirm(`是否确认${row.status==='0'?`禁用`:`启用`}设备编号为${noticeIds}的数据？`, '提示', {
      //     confirmButtonText: '确定',
      //     cancelButtonText: '取消',
      //     type: 'warning'
      //   }).then(()=> {
      //   this.loading = true;
      //   let params={
      //     equipmentAccountId:row.equipmentAccountId,
      //     userStatus: '1'
      //   }
      //   putaccounttenable(params).then(res=>{
      //     if(res.code === 200){
      //       this.loading = false;
      //       this.$message.success(res.msg)
      //       this.getList()
      //     }
      //   })
      // }).catch(() => {this.loading = false;});
    }
  },
  filters: {
  }
};
</script>
<style lang="scss" scoped>
.red {
  color: red;
}

.flex_right {
  position: absolute;
  top: -50px;
  right: 0px
}
</style>